<template>
  <article class="article-card" @click="handleClick">
    <div class="article-image">
      <div class="image-placeholder" :style="{ background: article.color }">
        <span class="image-icon">{{ article.icon }}</span>
      </div>
      <a-tag :color="categoryColor" class="article-category-tag">
        {{ article.categoryName }}
      </a-tag>
    </div>
    <div class="article-content">
      <h3 class="article-title">{{ article.title }}</h3>
      <p class="article-excerpt">{{ article.excerpt }}</p>
      <div class="article-meta">
        <span class="article-date">{{ article.date }}</span>
        <span class="article-read-count">{{ article.readCount }} 人阅读</span>
      </div>
      <div class="article-tags">
        <a-tag v-for="tag in article.tags" :key="tag" class="article-tag" color="blue">
          {{ tag }}
        </a-tag>
      </div>
    </div>
    <div class="article-hover">
      <div class="hover-content">
        <div class="hover-icon">📖</div>
        <div class="hover-title">阅读全文</div>
      </div>
    </div>
  </article>
</template>

<script setup lang="ts">
  import { computed } from 'vue';
  import { Tag as ATag } from 'ant-design-vue';

  interface Article {
    id: number;
    icon: string;
    color: string;
    category: string;
    categoryName: string;
    title: string;
    excerpt: string;
    date: string;
    readCount: number;
    tags: string[];
  }

  const props = defineProps<{
    article: Article;
    categoryColor?: string;
  }>();
  const emit = defineEmits<{
    (e: 'click', article: Article): void;
  }>();

  const handleClick = () => {
    emit('click', props.article);
  };

  const categoryColor = computed(() => props.categoryColor || 'blue');
</script>

<style scoped lang="scss">
  .article-card {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    height: 380px;
  }

  .article-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 60px rgba(24, 144, 255, 0.2);
    border-color: rgba(24, 144, 255, 0.4);
  }

  .article-image {
    position: relative;
    height: 140px;
    flex-shrink: 0;
  }

  .image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: #fff;
    border-radius: 16px 16px 0 0;
    transition: background 0.3s;
  }

  .article-category-tag {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 0.8rem;
    border-radius: 12px;
    padding: 4px 10px;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .article-content {
    padding: 1rem 1.2rem 1rem 1.2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .article-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    margin: 0 0 0.6rem 0;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.8rem;
  }

  .article-excerpt {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    margin: 0 0 0.8rem 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
    min-height: 2.7rem;
  }

  .article-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    margin-bottom: 0.6rem;
    font-weight: 500;
  }

  .article-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .article-tag {
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: white !important;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 10px !important;
    padding: 2px 8px !important;
    backdrop-filter: blur(10px);
  }

  .article-hover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
    border-radius: 16px;
  }

  .article-card:hover .article-hover {
    opacity: 1;
  }

  .hover-content {
    text-align: center;
    animation: pulse 2s infinite;
  }

  .hover-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 8px rgba(24, 144, 255, 0.5));
  }

  .hover-title {
    font-size: 1rem;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  }

  @keyframes pulse {
    0%,
    100% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.03);
    }
  }

  @media (max-width: 768px) {
    .article-card {
      height: 360px;
      border-radius: 12px;
    }
    .article-content {
      padding: 0.8rem 1rem 0.8rem 1rem;
    }
    .article-title {
      font-size: 1rem;
      min-height: 2.4rem;
    }
    .article-excerpt {
      font-size: 0.85rem;
      min-height: 2.4rem;
    }
    .image-placeholder {
      font-size: 2rem;
    }
    .article-image {
      height: 120px;
    }
  }
</style>
